// columns.ts

import DictTag, { DictValueEnum } from "@/components/DictTag";
import { QuestionCircleOutlined } from "@ant-design/icons";
import { ProColumns } from "@ant-design/pro-table";
import { Avatar, Divider, Dropdown, Image, MenuProps, Popconfirm, Space, Switch, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	fileTypeOptions: DictValueEnum,
	handleColumnRemove: (record: API.Setting.StorageFileVo) => void,
	handleColumnDownload: (record: API.Setting.StorageFileVo) => void,
	handleColumnDetails: (record: API.Setting.StorageFileVo) => void
): ProColumns<API.Setting.StorageFileVo>[] => {
	return [
		{
			title: "原名称",
			dataIndex: "originalName",
			valueType: "text",
			ellipsis: true,
			render: (_, record) => (
				<Typography.Link
					onClick={() => {
						handleColumnDetails(record);
					}}
				>
					{record?.originalName}
				</Typography.Link>
			)
		},
		{
			title: "文件类型",
			dataIndex: "fileType",
			valueType: "select",
			filters: true,
			search: false,
			onFilter: true,
			valueEnum: fileTypeOptions,
			render: (_, record) => {
				return <DictTag type="tag" defaultValue="未知" enums={fileTypeOptions} value={record?.fileType} />;
			}
		},
		{
			title: "文件大小",
			dataIndex: "fileSize",
			valueType: "text",
			sorter: true,
			search: false
		},
		{
			title: "上传人",
			dataIndex: "createByName",
			valueType: "text",
			search: false
		},
		{
			title: "上传时间",
			dataIndex: "createTime",
			valueType: "date",
			search: false,
			sorter: true
		},
		{
			title: "上传时间",
			dataIndex: "createTime",
			valueType: "dateRange",
			ellipsis: true,
			hideInTable: true,
			search: {
				transform: value => {
					return {
						beginTime: value[0],
						endTime: value[1]
					};
				}
			}
		},
		{
			title: "操作",
			dataIndex: "option",
			width: "220px",
			valueType: "option",
			fixed: "right",
			render: (_, record: any) => {
				return (
					record?.id !== 1 && (
						<>
							<Space size={1} split={<Divider type="vertical" />}>
								<Typography.Link
									key="download"
									onClick={() => {
										handleColumnDownload(record?.id);
									}}
								>
									下载
								</Typography.Link>
								<Typography.Link
									key="details"
									onClick={() => {
										// setModalVisible(true);
										// setDataSource(record);
										// setCurrentId(record?.id);
										// setDetailOpen(true);
										handleColumnDetails(record);
									}}
								>
									详情
								</Typography.Link>
								<Popconfirm
									placement="bottomRight"
									title="提示"
									description={`确认要删除文件名称: "${record?.originalName}" 的文件吗？`}
									key="remove"
									onConfirm={async () => handleColumnRemove(record.id)}
									okText="确认"
									cancelText="取消"
								>
									<Typography.Link type="danger" key="removeBtn">
										删除
									</Typography.Link>
								</Popconfirm>
							</Space>
						</>
					)
				);
			}
		}
	];
};
const listOperItem: MenuProps["items"] = [
	{
		label: "重置密码",
		key: "restPassword"
	},
	{
		label: "授权角色",
		key: "authRole"
	}
];
export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const pagination = {
	showQuickJumper: true,
	showSizeChanger: true
};

export const formTitle = ["添加用户", "编辑用户"];
